$(function(){
    console.log('来自于demo04');

    var stars = $('.stars');
    stars.each(function(){
        var star = $(this).children('i');
        var starNumTag = $(this).find('em');
        var starNum = starNumTag.attr('starNum');

        function fnstar(index){
            star.removeClass('active');
            for( var i=0; i<=index; i++ ){
                star.eq(i).addClass('active');
            }
            starNumTag.text(index+1);
        }

        star.hover(function(){
            var index = $(this).index();
            fnstar(index);
        },function(){
            fnstar(starNum-1);
        });

        star.click(function(){
            var index = $(this).index();
            starNum = index+1;
            fnstar(index);
        });
    });
});